#include "CardSet.h"

using namespace Cards;

CardSet::CardSet(void)
{
}

void CardSet::add(Card* card)
{
	cards.insert(card);
}

bool CardSet::contains(Card* card)
{
	return cards.count(card) > 0;
}

bool CardSet::empty()
{
	return cards.empty();
}

int CardSet::size() const
{
	return cards.size();
}

CardSet CardSet::intersect(CardSet& other_cards_set)
{
	CardSet common_cards_set;
	for(CardSet::Iterator i = other_cards_set.begin(); i != other_cards_set.end(); ++i)
	{
		if (this->contains(*i)) {
			common_cards_set.add(*i);
		}
	}
	return common_cards_set;
}

CardSet::Iterator CardSet::begin() const
{
	return CardSet::Iterator(cards.begin());
}

CardSet::Iterator CardSet::end() const
{
	return CardSet::Iterator(cards.end());
}

CardSet::Iterator::Iterator(std::set<Card*>::iterator iterator): iterator(iterator)
{
}

CardSet::Iterator& CardSet::Iterator::operator++()
{
	++iterator;
	return *this;
}

CardSet::Iterator CardSet::Iterator::operator++(int)
{
	CardSet::Iterator tmp(*this);
	operator++();
	return tmp;
}

bool CardSet::Iterator::operator==(const CardSet::Iterator& rhs) const
{
	return iterator==rhs.iterator;
}

bool CardSet::Iterator::operator!=(const CardSet::Iterator& rhs) const
{
	return iterator!=rhs.iterator;
}

Card* CardSet::Iterator::operator*()
{
	return *iterator;
}

bool CardSet::operator==(const CardSet& rhs)
{
	return this->cards == rhs.cards;
}

